<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>删除有序数组中的重复项II</title>
</head>
<body>
  <script>
    function fn(nums) {
      if (nums.length < 3) return nums.length
      for (let i = 2; i < nums.length; i++) {
        if (nums[i] === nums[i - 2]) {
          nums.splice(i, 1)
          i--
        }
      }
      return nums.length
    }
    console.log(fn([1, 1, 1, 2, 2, 3]))
  </script>
</body>
</html>